package com.sitech.openapi.controller.customer;

import com.sitech.openapi.componet.SetHttpHeaderCmpt;
import com.sitech.openapi.controller.AbstractController;
import com.sitech.openapi.domain.customer.Customer;
import com.sitech.openapi.service.CustomerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Api(tags = "客户信息查询控制层",description = "查询客户相关信息")
@RestController
public class QryCustomerInfoController extends AbstractController{

    @Autowired
    private CustomerService customerService;
    @Autowired
    private SetHttpHeaderCmpt setHttpHeaderCmpt;

    @GetMapping("/customerSX")
    @ApiOperation(value = "查询客户信息",notes = "查询客户信息")
    public ResponseEntity<List<Customer>> queryCustomerInfo(@RequestParam(required = false) String accNum,
                                                    @RequestParam(required = false) String certType,
                                                    @RequestParam(required = false) String certNum,
                                                    @RequestParam(required = false) Integer limit,
                                                    @RequestParam(required = false) Integer offset,
                                                    @RequestHeader HttpHeaders headers){

        Map<String,Object> map = new HashMap<>();
        map.put("accNum",accNum);
        map.put("certType",certType);
        map.put("certNum",certNum);
        map.put("pageSize",limit);
        map.put("pageIndex",offset);

        Map<String,Object> resMap = customerService.getCustomerInfo(map);
        List<Customer> customers = (List<Customer>) resMap.get("dataList");
        String total = Long.toString((Long)resMap.get("total"));
        HttpHeaders httpHeaders = setHttpHeaderCmpt.setOKHttpHeaders(headers);
        httpHeaders.set("X-Total-Count",total);
        ResponseEntity<List<Customer>> res = new ResponseEntity<List<Customer>>(customers,httpHeaders, HttpStatus.OK);
        return res;
    }
    
}
